module "flip"

buttons = {}

local prev_update = update

function update()
	local ret = prev_update()

	while true do
		local ev, data = next_event()
		if not ev then break end

		if ev == "button" then
			if data.state then
				buttons[data.id] = true
			else
				buttons[data.id] = false
			end
		end

		on_event(ev, data)
	end

	return ret
end

function on_event()
	-- Nothing by default
end